package com.bdyc.service.springImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.bdyc.controller.custom.OrderGroup;
import com.bdyc.controller.custom.OrderInfoPo;
import com.bdyc.dao.OrderInfoMapper;
import com.bdyc.service.spring.OrderInfoService;
@Service("orderInfoService")
public class OrderInfoServiceImpl implements OrderInfoService {
	@Autowired(required=true)
	@Qualifier("orderInfoMapper")
	private OrderInfoMapper orderInfoMapper;

	public List<OrderInfoPo> findOrderInfoList(Map<String, Object> map) {
		//设置limit起始索引 (currentPage-1)*pageSize
			Integer currentPage = (Integer)map.get("page");
			Integer pageSize  = (Integer)map.get("rows");
			//封装查询记录数map
			Integer count = orderInfoMapper.findOrderInfoListCount(map);
			if(count >0){
				Integer index = count/pageSize;
				System.out.println(count%pageSize);
				Integer sum = count%pageSize==0?index:index +1;
				if(currentPage == null || currentPage <= 0){
					currentPage =1;
				}
				if(currentPage > sum ){
					currentPage=sum ;
				}
				map.put("currentPage",  (currentPage-1)*pageSize);
				map.put("pageSize", pageSize);
			}
			return orderInfoMapper.findOrderInfoList(map);
	}
	//分页查询总记录数
	public Integer findOrderInfoListCount(Map<String, Object> sendMap) {
		return orderInfoMapper.findOrderInfoListCount(sendMap);
	}
	//分组查询flag
	public List<OrderGroup> groupFlag() {
		return orderInfoMapper.groupFlag();
	}
	//分组查询status
	public List<OrderGroup> groupStatus(Integer flag) {
		return orderInfoMapper.groupStatus(flag);
	}


}
